<?php

namespace Addons\OaSystem\Controller;

class OaNavMenuController extends OaBaseController
{
    protected $model;

    function _initialize()
    {
        $this->model = $this->getModel('oa_nav_menu');
        parent::_initialize();

    }

    function lists(){
        $list_data = $this->_get_model_list( $this->model );
        $grids = $list_data['list_grids'];
        //$data = $list_data['list_data'];
        $data = db_select('oa_nav_menu');
        foreach ($data as $i => $v) {
            $editUrl = U('edit', array('id'=> $v['id']));
            $delUrl = U('del', array('id'=> $v['id']));
            $data[$i]['urls'] = "<a href=$editUrl>编辑</a>".'   '."<a class='confirm' href=$delUrl>删除</a>";
        }

        $this -> assign('list_grids', $grids);
        $this->assign('list_data', $data);
        $this->display();
    }

    function add(){
        if(IS_POST) {
            $data['title'] = $_POST['title'];
            $data['controller'] = $_POST['controller'];
            $data['action'] = $_POST['action'];
            $data['url'] = $_POST['url'];
            $data['pid'] = $_POST['pid'];
            $data['sort'] = $_POST['sort'];
            $sel_roles = array();
            $roles = db_select('oa_role');
            foreach($roles as $vo) {
                if($_POST[$vo['name']] == 1)
                    array_push($sel_roles, intval($vo['id']));
            }
            $data['roles'] = json_encode($sel_roles);
            if(M('oa_nav_menu')->add($data))
                $this->success ( '创建' . $model ['title'] . '成功！', U ( 'lists?model=' . $model ['name'], $this->get_param ));
        } else {
            $roles = db_select('oa_role');
            $this->assign('roles', $roles);
            $this->display('add');
        }
    }

    function edit()
    {
        if(IS_POST) {
            $id = $_POST['id'];
            $data['title'] = $_POST['title'];
            $data['controller'] = $_POST['controller'];
            $data['action'] = $_POST['action'];
            $data['url'] = $_POST['url'];
            $data['pid'] = $_POST['pid'];
            $data['sort'] = $_POST['sort'];
            $sel_roles = array();
            $roles = db_select('oa_role');
            foreach($roles as $vo) {
                if($_POST[$vo['name']] == 1)
                    array_push($sel_roles, intval($vo['id']));
            }
            $data['roles'] = json_encode($sel_roles);
            if(M('oa_nav_menu')->where(['id'=>$id])->save($data))
                $this->success ( '修改' . $model ['title'] . '成功！', U ( 'lists?model=' . $model ['name'], $this->get_param ));
        } else {
            $id = $_GET['id'];
            $nav_menu = db_find('oa_nav_menu', ['id'=>$id]);
            $menu_roles = json_decode($nav_menu['roles'], true);
            $roles = db_select('oa_role');
            foreach ($roles as $i => $v) {
                if(in_array($v['id'], $menu_roles))
                    $roles[$i]['checked'] = 'checked';
            }
            $this->assign('data', $nav_menu);
            $this->assign('roles', $roles);
            $this->display();
        }
    }

    function addduty() {
        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
        foreach ($dept2 as $i => $v) {
            $duty = array();
            $duty['appid'] = $this->appId;
            $duty['duty_no'] = sprintf("%06d", $i*2+11);
            $duty['name'] = $v['name'].'.处长';
            $duty['is_del'] = 0;
            $duty['level'] = 16;
            M('oa_duty')->add($duty);
            $duty['duty_no'] = sprintf("%06d", $i*2+12);
            $duty['name'] = $v['name'].'.副处长';
            $duty['level'] = 15;
            M('oa_duty')->add($duty);
        }

        $dept3 = db_select('oa_dept', ['dept_grade_id'=>3], 'dept_no asc');
        foreach ($dept3 as $i => $v) {
            $pdept = db_find('oa_dept', ['id'=>$v['pid']]);
            $duty = array();
            $duty['appid'] = $this->appId;
            $duty['duty_no'] = sprintf("%06d", $i*2+101);
            $duty['name'] = $pdept['name'].'.'.$v['name'].'.科长';
            $duty['is_del'] = 0;
            $duty['level'] = 12;
            M('oa_duty')->add($duty);
            $duty['duty_no'] = sprintf("%06d", $i*2+102);
            $duty['name'] = $pdept['name'].'.'.$v['name'].'.副科长';
            $duty['level'] = 11;
            M('oa_duty')->add($duty);
        }
    }

    function addrole() {
//        $sort = 20;
//        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
//        foreach ($dept2 as $i => $v) {
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $v['name'].'.部门报销审核';
//            $role['sort'] = $sort++;
//            $role['role_level'] = $v['dept_grade_id'];
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '指具有部门初核权限的处长，初核该处的员工报销。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }
//
//        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
//        foreach ($dept2 as $i => $v) {
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $v['name'].'.正处加班审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 16;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '正处级领导审批该处室员工加班申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//            $role['name'] = $v['name'].'.副处加班审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 15;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '副处级领导审批该处室员工加班申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }
//
//        $dept3 = db_select('oa_dept', ['dept_grade_id'=>3], 'dept_no asc');
//        foreach ($dept3 as $i => $v) {
//            $pdept = db_find('oa_dept', ['id'=>$v['pid']]);
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $pdept['name'].'.'.$v['name'].'.正科加班审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 12;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '正科级领导审批该科室员工加班申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//            $role['name'] = $pdept['name'].'.'.$v['name'].'.副科加班审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 11;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '副科级领导审批该科室员工加班申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }
//
//        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
//        foreach ($dept2 as $i => $v) {
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $v['name'].'.正处休假审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 16;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '正处级领导审批该处室员工休假申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//            $role['name'] = $v['name'].'.副处休假审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 15;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '副处级领导审批该处室员工休假申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }
//
//        $dept3 = db_select('oa_dept', ['dept_grade_id'=>3], 'dept_no asc');
//        foreach ($dept3 as $i => $v) {
//            $pdept = db_find('oa_dept', ['id'=>$v['pid']]);
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $pdept['name'].'.'.$v['name'].'.正科休假审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 12;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '正科级领导审批该科室员工休假申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//            $role['name'] = $pdept['name'].'.'.$v['name'].'.副科休假审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 11;
//            $role['role_scope'] = 'S';
//            $role['role_description'] = '副科级领导审批该科室员工休假申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }
        //每个处室加一个分管副关角色
//        $sort = 200;
//        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
//        foreach ($dept2 as $i => $v) {
//            $role = array();
//            $role['appid'] = $this->appId;
//            $role['name'] = $v['name'].'_副关加班审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 19;
//            $role['role_scope'] = 'G';
//            $role['role_description'] = '副关长审批分管处室领导的加班申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//            $role['name'] = $v['name'].'_副关休假审批';
//            $role['sort'] = $sort++;
//            $role['role_level'] = 19;
//            $role['role_scope'] = 'G';
//            $role['role_description'] = '副关长审批分管处室领导的休假申请。';
//            $role['dept_id'] = $v['id'];
//            M('oa_role')->add($role);
//        }

    }

    function adddutyrole() {

        $data['appid'] = $this->appId;

//        //加员工角色
//        $map['id'] = array('gt', 18);
//        $duty = db_select('oa_duty', $map);
//        $role = db_find('oa_role', ['name'=>'员工']);
//        foreach ($duty as $v) {
//            $data['role_id'] = $role['id'];
//            $data['duty_id'] = $v['id'];
//            M('oa_role_duty')->add($data);
//        }
//
//        //加 部门报销审核角色
//        $map['level'] = 16;
//        $duty = db_select('oa_duty', $map);
//        foreach ($duty as $i => $v) {
//            $dutyname = explode('.', $v['name']);
//            if(count($dutyname) < 2)
//                continue;
//            $rolename = $dutyname[0].'.部门报销审核';
//            $role = db_find('oa_role', ['name'=>$rolename]);
//            $data['role_id'] = $role['id'];
//            $data['duty_id'] = $v['id'];
//            M('oa_role_duty')->add($data);
//        }
//
//        //加 加班审批角色
//        $map['level'] = array('in', '11,12,15,16');
//        $duty = db_select('oa_duty', $map);
//        foreach ($duty as $i => $v) {
//            $dutyname = explode('.', $v['name']);
//            if(count($dutyname) < 2)
//                continue;
//            if($v['level'] == 11)
//                $rolename = $dutyname[0].'.'.$dutyname[1].'.副科加班审批';
//            if($v['level'] == 12)
//                $rolename = $dutyname[0].'.'.$dutyname[1].'.正科加班审批';
//            if($v['level'] == 15)
//                $rolename = $dutyname[0].'.副处加班审批';
//            if($v['level'] == 16)
//                $rolename = $dutyname[0].'.正处加班审批';
//            $role = db_find('oa_role', ['name'=>$rolename]);
//            $data['role_id'] = $role['id'];
//            $data['duty_id'] = $v['id'];
//            M('oa_role_duty')->add($data);
//        }
//
//        //加 休假审批角色
//        $map['level'] = array('in', '11,12,15,16');
//        $duty = db_select('oa_duty', $map);
//        foreach ($duty as $i => $v) {
//            $dutyname = explode('.', $v['name']);
//            if(count($dutyname) < 2)
//                continue;
//            if($v['level'] == 11)
//                $rolename = $dutyname[0].'.'.$dutyname[1].'.副科休假审批';
//            if($v['level'] == 12)
//                $rolename = $dutyname[0].'.'.$dutyname[1].'.正科休假审批';
//            if($v['level'] == 15)
//                $rolename = $dutyname[0].'.副处休假审批';
//            if($v['level'] == 16)
//                $rolename = $dutyname[0].'.正处休假审批';
//            $role = db_find('oa_role', ['name'=>$rolename]);
//            $data['role_id'] = $role['id'];
//            $data['duty_id'] = $v['id'];
//            M('oa_role_duty')->add($data);
//        }

        //都加上提交申请
        $dutys = db_select('oa_duty');
        foreach ($dutys as $v) {
            $data['role_id'] = 783;
            $data['duty_id'] = $v['id'];
            if(!db_find('oa_role_duty', $data))
                M('oa_role_duty')->add($data);
        }
    }

    function removerepeat() {
        $roles = db_select('oa_role');
        foreach ($roles as $v) {
            $tmp = db_select('oa_role', ['name'=>$v['name']], 'id asc');
            for($i = 1; $i < count($tmp); $i++) {
                M('oa_role')->where(['id'=>$tmp[$i]['id']])->delete();
            }
        }

        $dutys = db_select('oa_duty');
        foreach ($dutys as $v) {
            $tmp = db_select('oa_duty', ['name'=>$v['name']], 'id asc');
            for($i = 1; $i < count($tmp); $i++) {
                M('oa_duty')->where(['id'=>$tmp[$i]['id']])->delete();
            }
        }
    }

    function change() {
        $dutys = db_select('oa_role');
        foreach ($dutys as $v) {
            $data['name'] = str_replace('.', '_', $v['name']);
            db_save('oa_role', ['id'=>$v['id']], $data);
        }
    }

    function addprocessflow() {
        //处级加班休假流程
//        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
//        foreach ($dept2 as $v) {
//            $data = array();
//            $attr = array(
//                'type' => 'OaRole',
//                'len' => 3,
//                'dept' => intval($v['id'])
//            );
//
//            $rolename1 = $v['name'].'_副处加班审批';
//            $rolename2 = $v['name'].'_正处加班审批';
//            $rolename3 = $v['name'].'_副关加班审批';
//            $role1 = db_find('oa_role', ['name'=>$rolename1]);
//            $role2 = db_find('oa_role', ['name'=>$rolename2]);
//            $role3 = db_find('oa_role', ['name'=>$rolename3]);
//            $operation[0] = 783; //提交
//            $operation[1] = intval($role1['id']); //副处
//            $operation[2] = intval($role2['id']); //正处
//            $operation[3] = intval($role3['id']); //副关
//            $operation[4] = 40;
//            $operation[5] = 51;
//
//            $data['appid'] = $this->appId;
//            $data['name'] = $v['name'].'_加班审批流程';
//            $data['type'] = 1;
//            $data['attr'] = json_encode($attr);
//            $data['operations'] = json_encode($operation);
//
//                if(db_find('oa_process_flow', $data) == NULL) {
//                    M('oa_process_flow')->add($data);
//                }
//
//            /////////////////////////////////////
//
//            $rolename1 = $v['name'].'_副处休假审批';
//            $rolename2 = $v['name'].'_正处休假审批';
//            $rolename3 = $v['name'].'_副关休假审批';
//            $role1 = db_find('oa_role', ['name'=>$rolename1]);
//            $role2 = db_find('oa_role', ['name'=>$rolename2]);
//            $role3 = db_find('oa_role', ['name'=>$rolename3]);
//            $operation[0] = 783; //提交
//            $operation[1] = intval($role1['id']); //副处
//            $operation[2] = intval($role2['id']); //正处
//            $operation[3] = intval($role3['id']); //副关
//            $operation[4] = 57;
//            $operation[5] = 51;
//
//            $data['appid'] = $this->appId;
//            $data['name'] = $v['name'].'_休假审批流程';
//            $data['type'] = 2;
//            $data['attr'] = json_encode($attr);
//            $data['operations'] = json_encode($operation);
//
//        if(db_find('oa_process_flow', $data) == NULL) {
//            M('oa_process_flow')->add($data);
//        }
//        }

//        $dept3 = db_select('oa_dept', ['dept_grade_id'=>3], 'dept_no asc');
//        foreach ($dept3 as $v) {
//            $data = array();
//            $pdept = db_find('oa_dept', ['id'=>$v['pid']]);
//            $attr = array(
//                'type' => 'OaRole',
//                'len' => 3,
//                'dept' => intval($pdept['id']),
//                'ke_dept' => intval($v['id']),
//            );
//            $rolename1 = $pdept['name'].'_'.$v['name'].'_副科加班审批';
//            $rolename2 = $pdept['name'].'_'.$v['name'].'_正科加班审批';
//            $rolename3 = $pdept['name'].'_副处加班审批';
//            $rolename4 = $pdept['name'].'_正处加班审批';
//            $rolename5 = $pdept['name'].'_副关加班审批';
//            $role1 = db_find('oa_role', ['name'=>$rolename1]);
//            $role2 = db_find('oa_role', ['name'=>$rolename2]);
//            $role3 = db_find('oa_role', ['name'=>$rolename3]);
//            $role4 = db_find('oa_role', ['name'=>$rolename4]);
//            $role5 = db_find('oa_role', ['name'=>$rolename5]);
//            $operation[0] = 783; //提交
//            $operation[1] = intval($role1['id']); //副科
//            $operation[2] = intval($role2['id']); //正科
//            $operation[3] = intval($role3['id']); //副处
//            $operation[4] = intval($role4['id']); //正处
//            $operation[5] = intval($role5['id']); //副关
//            $operation[6] = 40;
//            $operation[7] = 51;
//
//            $data['appid'] = $this->appId;
//            $data['name'] = $pdept['name'].'_'.$v['name'].'_加班审批流程';
//            $data['type'] = 1;
//            $data['attr'] = json_encode($attr);
//            $data['operations'] = json_encode($operation);
//
//            if(db_find('oa_process_flow', $data) == NULL) {
//                M('oa_process_flow')->add($data);
//            }
//
//            /////////////////////////////////////
//
//            $rolename1 = $pdept['name'].'_'.$v['name'].'_副科休假审批';
//            $rolename2 = $pdept['name'].'_'.$v['name'].'_正科休假审批';
//            $rolename3 = $pdept['name'].'_副处休假审批';
//            $rolename4 = $pdept['name'].'_正处休假审批';
//            $rolename5 = $pdept['name'].'_副关休假审批';
//            $role1 = db_find('oa_role', ['name'=>$rolename1]);
//            $role2 = db_find('oa_role', ['name'=>$rolename2]);
//            $role3 = db_find('oa_role', ['name'=>$rolename3]);
//            $role4 = db_find('oa_role', ['name'=>$rolename4]);
//            $role5 = db_find('oa_role', ['name'=>$rolename5]);
//            $operation[0] = 783; //提交
//            $operation[1] = intval($role1['id']); //副科
//            $operation[2] = intval($role2['id']); //正科
//            $operation[3] = intval($role3['id']); //副处
//            $operation[4] = intval($role4['id']); //正处
//            $operation[5] = intval($role5['id']); //副关
//            $operation[6] = 57;
//            $operation[7] = 51;
//
//            $data['appid'] = $this->appId;
//            $data['name'] = $pdept['name'].'_'.$v['name'].'_休假审批流程';
//            $data['type'] = 2;
//            $data['attr'] = json_encode($attr);
//            $data['operations'] = json_encode($operation);
//
//            if(db_find('oa_process_flow', $data) == NULL) {
//                M('oa_process_flow')->add($data);
//            }
//        }


        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
        foreach ($dept2 as $v) {
            $data = array();
            $attr = array(
                'type' => 'OaRole',
                'days' => array('min'=>0, 'max'=>3),
                'dept' => intval($v['id']),
                'duty_lvl' => array(6,9,11,12,15)
            );

            /////////////////三天内休假审批流程////////////////////
            $rolename = $v['name'].'_正处休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //正处休假审批
            $operation[2] = 51;

            $data['appid'] = $this->appId;
            $data['name'] = $v['name'].'_三天内休假审批流程';
            $data['type'] = 2;
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            /////////////////三天内正处级休假审批流程////////////////////
            $rolename = $v['name'].'_副关休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //副关休假审批
            $operation[2] = 51;

            $attr['duty_lvl'] = array(16);

            $data['name'] = $v['name'].'_三天内正处休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            //////////////////三天以上员工休假审批流程///////////////////
            $attr['duty_lvl'] = array(6,9,11,12);
            $attr['days'] = array('min'=>3, 'max'=>-1);

            $rolename = $v['name'].'_正处休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //正处休假审批
            $operation[2] = 784;
            $operation[3] = 51;

            $data['name'] = $v['name'].'_三天以上员工休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            //////////////////三天以上副处级休假审批流程///////////////////
            $attr['duty_lvl'] = array(15);
            $attr['days'] = array('min'=>3, 'max'=>-1);

            $rolename1 = $v['name'].'_正处休假审批';
            $rolename2 = $v['name'].'_副关休假审批';
            $role1 = db_find('oa_role', ['name'=>$rolename1]);
            $role2 = db_find('oa_role', ['name'=>$rolename2]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role1['id']); //正处休假审批
            $operation[2] = intval($role2['id']); //副关休假审批
            $operation[3] = 784;
            $operation[4] = 51;

            $data['name'] = $v['name'].'_三天以上副处级休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            //////////////////三天以上正处休假审批流程///////////////////
            $attr['duty_lvl'] = array(16);
            $attr['days'] = array('min'=>3, 'max'=>-1);
            $rolename = $v['name'].'_副关休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //副关休假审批
            $operation[2] = 57;
            $operation[3] = 784;
            $operation[4] = 51;


            $data['name'] = $v['name'].'_三天以上正处休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }
        }

        $dept3 = db_select('oa_dept', ['dept_grade_id'=>3], 'dept_no asc');
        foreach ($dept3 as $v) {
            $data = array();
            $attr = array(
                'type' => 'OaRole',
                'days' => array('min'=>0, 'max'=>3),
                'dept' => intval($v['id']),
                'duty_lvl' => array(6,9,11,12)
            );
            $pdept = db_find('oa_dept', ['id'=>$v['pid']]);

            /////////////////三天内休假审批流程////////////////////
            $rolename = $pdept['name'].'_正处休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //正处休假审批
            $operation[2] = 51;

            $data['appid'] = $this->appId;
            $data['name'] = $pdept['name'].'_'.$v['name'].'_三天内休假审批流程';
            $data['type'] = 2;
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            //////////////////三天以上科员休假审批流程///////////////////
            $attr['duty_lvl'] = array(6,9);
            $attr['days'] = array('min'=>3, 'max'=>-1);

            $rolename1 = $pdept['name'].'_'.$v['name'].'_正科休假审批';
            $rolename2 = $pdept['name'].'_正处休假审批';
            $role1 = db_find('oa_role', ['name'=>$rolename1]);
            $role2 = db_find('oa_role', ['name'=>$rolename2]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role1['id']); //正科休假审批
            $operation[2] = intval($role2['id']); //正处休假审批
            $operation[3] = 784;
            $operation[4] = 51;

            $data['name'] = $pdept['name'].'_'.$v['name'].'_三天以上科员休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }

            //////////////////三天以上科级休假审批流程///////////////////
            $attr['duty_lvl'] = array(11,12);
            $attr['days'] = array('min'=>3, 'max'=>-1);
            $rolename = $pdept['name'].'_正处休假审批';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $operation = array();
            $operation[0] = 783; //提交
            $operation[1] = intval($role['id']); //正处休假审批
            $operation[2] = 784;
            $operation[3] = 51;

            $data['name'] = $pdept['name'].'_'.$v['name'].'_三天以上科级休假审批流程';
            $data['attr'] = json_encode($attr);
            $data['operations'] = json_encode($operation);

            if(db_find('oa_process_flow', $data) == NULL) {
                M('oa_process_flow')->add($data);
            }
        }
    }

    function addrolenode() {

        //所有处级 初核 加到报销审核功能点
        $dept2 = db_select('oa_dept', ['dept_grade_id'=>2], 'dept_no asc');
        foreach ($dept2 as $v) {
            $rolename = $v['name'].'_部门报销审核';
            $role = db_find('oa_role', ['name'=>$rolename]);
            $data['appid'] = $this->appId;
            $data['role_id'] = $role['id'];
            $data['node_id'] = 2;
            $data['admin'] = 0;
            $data['read'] = 1;
            $data['write'] = 1;
            if(db_find('oa_role_node', $data) == NULL) {
                M('oa_role_node')->add($data);
            }
        }
    }

    function test() {
        $b = $this->workTime;
        myprint('$b', $b);
    }


}